'use strict';
module.exports = {
	/**
	 * XXXnameXXX
	 * @url client/pages/kh/get_access_token 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		const db = uniCloud.database();
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, _ } = util;
		let { uid, appid } = data;
		let res = { code: 0, msg: "" };
		// 业务逻辑开始-----------------------------------------------------------
		appid = "wx1e37ba916f0829bb";
		let gzhinfo = await db.collection('a_appid').where({ appid: appid }).get()

		if (!gzhinfo.data[0]) {
			res.msg = "未找到相关公众号";
			res.code = 1;
			return res;
		}
		let secret = gzhinfo.data[0].appsecret;
		let sendurl =
			"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" +
			secret;
		const send = await uniCloud.httpclient.request(sendurl, {
			method: 'GET',
			contentType: 'json', // 指定以application/json发送data内的数据
			dataType: 'json' // 指定返回值为json格式，自动进行parse
		})
		console.log("send=", send.data.access_token);
		

		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
